﻿using UnityEditor;
using UnityEngine.UIElements;

namespace NodeEditor
{
    /// <summary>
    /// 显示字段
    /// </summary>
    public class InspectorView : VisualElement
    {
        public new class UxmlFactory : UxmlFactory<InspectorView, VisualElement.UxmlTraits> { }

        Editor editor;

        public void OnUpdate(UnityEngine.Object @object)
        {
            if (@object == null)
                return;

            UnityEngine.Object.DestroyImmediate(editor);

            this.Clear();

            editor = Editor.CreateEditor(@object);

            if (editor == null)
                return;

            Add(new IMGUIContainer(editor.OnInspectorGUI));
        }
    }

}
